<?php
 require_once "../connect/toolconnect.php";
 session_start();
 if(empty($_SESSION['user'])) {
 echo("<script>alert('归还信息填写不完整！'); </script>");
	header("Location: ../login.php");
 }
$id=trim($_POST['ID']);
$ctr=trim($_GET['ctr']);
$number=trim($_POST['number']);
$name=trim($_POST['name']);
$translation=trim($_POST['translation']);
$time=trim($_POST['time']);
$score=trim($_POST['score']);
$Ffruit=trim($_POST['Ffruit']);
$Lfruit=trim($_POST['Lfruit']);
$temp_Lfruit="";
for($ii=0; $ii<sizeof($_POST['Lfruit']); $ii++) {
	$temp_Lfruit.=$_POST['Lfruit'][$ii].";;";
}
$Fnation=trim($_POST['Fnation']);
$Lnation=trim($_POST['Lnation']);
$temp_Lnation="";
for($ii=0; $ii<sizeof($_POST['Lnation']); $ii++) {
	$temp_Lnation.=$_POST['Lnation'][$ii].";;";
}
$sql_edit="update self_full_test set number='{$number}', name='{$name}', translation='{$translation}', time='{$time}', score='{$score}', Ffruit='{$Ffruit}', Lfruit='{$temp_Lfruit}', Fnation='{$Fnation}', Lnation='{$temp_Lnation}' where ID = {$id}";

$sql_add3="INSERT INTO self_full_test ( `number`, `name`, `translation`, `time`, `score`, `Ffruit`, `Lfruit`, `Fnation`, `Lnation`)values('{$number}', '{$name}', '{$translation}', '{$time}', '{$score}', '{$Ffruit}', '{$temp_Lfruit}', '{$Fnation}', '{$temp_Lnation}')";
$sql = "select * from self_full_test where ID= {$id}";
$rs = mysql_query($sql);
$row = mysql_fetch_assoc($rs);

if($ctr=='add'){
 	if($row['ID']==$id){
	echo "<script>alert('请勿重复添加！');</script>";
	}else{
		if(mysql_query($sql_add3)) {echo "<script>alert('添加成功！');</script>";}else{echo "<script>alert('添加失败！');</script>".$sql_add3;}
	}
}elseif($ctr=='edit'){
		if(mysql_query($sql_edit)) {echo "<script>alert('更新成功！');window.history.back();</script>";}
 }
?>